﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLBH.DTO;
using QLBH.DataModel;
using QLBH.Model.Controller;

namespace Module.Category.BL
{
    public class CalculateUnitManagementBL
    {
        private static CalculateUnitManagementBL instance;

        public static CalculateUnitManagementBL Instance
        {
            get 
            { 
                if (instance==null)
                {
                    instance = new CalculateUnitManagementBL();
                }
                return instance; 
            }
            
        }
        public CalculateUnitManagementBL()
        {

        }
        /// <summary>
        /// Get All Calculate Unit from database
        /// </summary>
        /// <returns></returns>
        public List<DVTDTO> GetAllCalUnits()
        {
            try
            {
                IEnumerable<DVT> calUnits = CalculateUnitController.Instance.GetAll();
                return DVTAssembler.ToDTOs(calUnits).ToList();
            }
            catch (System.Exception ex)
            {
            	throw ex;
            }
            
        }
        
        /// <summary>
        /// Update Calculate Unit
        /// </summary>
        /// <param name="editCalUnit"></param>
        /// <returns></returns>
        public bool UpdateCalUnit(DVTDTO editCalUnit)
        {
            try
            {
                DVT calUnit = DVTAssembler.ToEntity(editCalUnit);
                CalculateUnitController.Instance.Edit(calUnit);
                return true;
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

        }
        /// <summary>
        /// Delete Cal Units
        /// </summary>
        /// <param name="listCalUnits"></param>
        /// <returns></returns>
        public bool DeleteCalUnits(IList<DVTDTO> listCalUnits)
        {
            try
            {
                IList<DVT> calUnits = DVTAssembler.ToEntities(listCalUnits).ToList();
                CalculateUnitController.Instance.Deletes(calUnits);
                return true;
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Get Calculate Unit by ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DVTDTO GetCalculateUnit(int id)
        {
            return CalculateUnitController.Instance.FindBy(d => d.Id == id).ToDTOs().FirstOrDefault();
        }
    }
}
